package com.china.cibn.bangtvmobile.bangtv.widget;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by hcc on 16/9/20 00:47
 *
 * <p/>
 * 重写Viewpager解决点击tab去除滑动动画效果的问题
 */
public class NoScrollViewPager extends ViewPager {

  private boolean noScroll = false;

  public NoScrollViewPager(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
  }

  public NoScrollViewPager(Context context) {
    super(context);
  }

  public void setNoScroll(boolean noScroll) {
    this.noScroll = noScroll;
  }

  @Override
  public void scrollTo(int x, int y) {
    super.scrollTo(x, y);
  }

  @Override
  public boolean onTouchEvent(MotionEvent arg0) {
            /* return false;//super.onTouchEvent(arg0); */
    switch(arg0.getAction()){
    }


    return !noScroll && super.onTouchEvent(arg0);
  }

  @Override
  public boolean onInterceptTouchEvent(MotionEvent arg0) {
    return !noScroll && super.onInterceptTouchEvent(arg0);
  }

  @Override
  public void setCurrentItem(int item, boolean smoothScroll) {
    super.setCurrentItem(item, smoothScroll);
  }

  @Override
  public void setCurrentItem(int item) {
    //false 去除滚动效果
    super.setCurrentItem(item,false);
  }

}
